<?php

	class SearchModel extends Model {
		/**
		 * 获得专业名称
		 * @param int $code 专业代码
		 * @return 参数为空，获取全部专业代码级名称，否则返回对应的专业名称
		 */
		public function getMajor($code){
			$get=M("Codetoname");
			if (empty($code)) {
				$where["type"]="major";
				$major=$get->where($where)->getField("code,name");
			}else{
				$where["type"]="major";
				$where["code"]=(int)$code;
				$major=$get->where($where)->getField("name");
			}
			return $major;
		}
		/**
		 * 获得院系信息
		 * @param $code 院系代码
		 * @return 参数为空，获取全部院系代码级名称，否则返回对应的院系名称
		 */
		public function getAcademy($code){
			$get=M("Codetoname");
			if (empty($code)) {
				$where["type"]="academy";
				$major=$get->where($where)->getField("code,name");
			}else{
				$where["type"]="academy";
				$where["code"]=(int)$code;
				$academy=$get->where($where)->getField("name");
			}
			return $academy;
		}
		/**
		 * 通过专业代码获取班级信息
		 * @param string $majorCode
		 * @return 班级信息列表 班级代码，班级名称
		 */
		public function getClass($majorCode,$class){
			$get=M("Codetoname");
			$where["type"]=(int)$majorCode;
			$where["code"]=(int)$class;
			$name=$get->where($where)->getField("name");
			return $name;
		}
		/**
		 * 获得班级成员列表
		 * @param int $classCode 班级代码
		 * @param int $grade 年级
		 * @return array
		 */
		public function getClassMemberList($grade,$major,$class,$field="sid,idcard,name,sex,phone,nation,birthplace"){
			$member=M("Baseinfo");
			$where['class']=(int)$class;
			$where['grade']=(int)$grade;
			$where['major']=(int)$major;
			$list=$member->where($where)->field($field)->select();
			return $list; 
		}
		/**
		 * 得到一个学生的详细信息
		 * @param unknown $sid 学号
		 * @param unknown $type 类型
		 * @param number $year 有年份的话读取年份
		 * @return multitype:|Ambigous <mixed, NULL, multitype:Ambigous <unknown, string> unknown , multitype:>
		 */
		public function getOnedetail($sid,$type,$year=0){
			$where["sid"]=$sid;
			switch ($type){
				case "base":
					$detail=M("Baseinfo")->where($where)->field("password",true)->select();
					break;
				case "family":
					$detail=M("Familyinfo")->where($where)->select();
					break;
				case "sanction":
					$where["year"]=$year;
					$detail=M("Sanctioninfo")->where($where)->select();
					unset($where["year"]);
					break;
				case "help":
					$detail=M("Helpinfo")->where($where)->select();
					break;
				case "party":
					$detail=M("Partyinfo")->where($where)->select();
					break;
				case "classjob":
					$where["year"]=$year;
					$detail=M("Classjobinfo")->where($where)->select();
					unset($where["year"]);
					break;
				case "remark":
					$detail=M("Remark")->where($where)->getField("remark");
					break;
				default:
					return array();
			}
			return $detail;
		}
	/**
	 * 根据相应的条件查找Baseinfo
	 * @param Array $where
	 * @return Ambigous <mixed, boolean, NULL, string, unknown, multitype:, multitype:multitype: , void, object>
	 */
		public function searchAtBase($where){
			$search=M("Baseinfo");
			$result=$search->where($where)->field("password",true)->select();
			if ($result) {
				return $result;
			}
		}
		public function getClassByList($grade,$major,$class,$field="workplace,job"){
			$by=M("Graduate");
			$where["grade"]=$grade;
			$where["major"]=$major;
			$where["class"]=$class;
			$where["isby"]=1;
			return $by->where($where)->field($field)->select();
		}
	}

?>